package com.alpha.controller;//package com.boostor.common.controller;

import com.alpha.pojo.dto.SysJobLogDTO;
import com.alpha.service.SysJobLogService;
import com.alpha.utils.msg.QueryReqBean;
import com.alpha.utils.msg.QueryRespBean;
import com.alpha.utils.msg.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 调度日志操作处理
 *
 * @author
 */
@RestController
@RequestMapping("/api/uf/boostor/common/jobLog")
public class SysJobLogController{

    @Autowired
    private SysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @PostMapping("/searchByPage/v1")
    public ResponseMsg<QueryRespBean<SysJobLogDTO>> searchByPage(@RequestBody QueryReqBean<SysJobLogDTO> queryReqBean) {
        return ResponseMsg.OK(jobLogService.searchByPage(queryReqBean));
    }

    /**
     * 根据调度编号获取详细信息
     */
    @GetMapping(value = "/{configId}")
    public ResponseMsg<SysJobLogDTO> getInfo(@PathVariable Long jobLogId) {
        return ResponseMsg.OK(jobLogService.selectJobLogById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */
    @DeleteMapping("/remove/v1/{jobLogIds}")
    public ResponseMsg remove(@PathVariable Long[] jobLogIds) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        int delLogIds = jobLogService.deleteJobLogByIds(jobLogIds);
        responseMsg.setResponseBody(delLogIds);
        responseMsg.setMessage(delLogIds > 0 ? "success" : "error");
        return responseMsg;
    }

    /**
     * 清空定时任务调度日志
     */
    @DeleteMapping("/clean")
    public ResponseMsg<Integer> clean() {
        jobLogService.cleanJobLog();
        return ResponseMsg.OK();
    }
}
